<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm">
                        <input id="id" name="id" th:value="${info.id}" maxlength="15"
                               class="form-control" type="hidden">
                        <input id="detailType" name="detailType" value="1"
                               class="form-control" type="hidden">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">名称：</label>
                            <div class="col-sm-8">
                                <input id="title" name="title" maxlength="20" th:value="${info.title}"
                                       class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">图片key：</label>
                            <div class="col-sm-8">
                                <input id="pictureUrl" name="pictureUrl" type="hidden" th:value="${info.pictureUrl}">
                                <input id="file"  style="display: none" type="file" hidden  onchange="getFile(this)" >
                                <div class="layui-upload">
                                    <button type="button" class="btn btn-primary" id="imgUpload" onclick="chooseFile()">选择文件</button>
<!--                                    <button type="button" class="btn btn-primary" id="addBut" onclick="uploadFile()">开始上传</button>-->
                                </div>
                                <img id="imgUrl" th:src="${info.pictureUrl}" onerror="this.src='/img/empty.jpg'" width="300px" height="200px"/>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label ">类型：</label>
                            <div class="col-sm-8">
                                <select data-placeholder="赛事类型" id="isIo" name="isIo" class="form-control chosen-select" onclick="selectChange()" tabindex="2" style="width: 100%">
                                    <option value="2" th:style="${info.isIo == 2 ? 'selected':''}">外链</option>
                                    <option value="1" th:style="${info.isIo == 1 ? 'selected':''}">内链</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group" id="types" style="display: none">
                            <label class="col-sm-3 control-label ">类型：</label>
                            <div class="col-sm-8">
                                <select data-placeholder="赛事类型" id="detailShowType" name="detailShowType" class="form-control chosen-select" tabindex="2" style="width: 100%">
                                    <option value="4" th:style="${info.detailShowType == 4 ? 'selected':''}">赛事详情</option>
<!--                                    <option value="3" th:style="${info.detailShowType == 3 ? 'selected':''}">模块</option>-->
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">链接：</label>
                            <div class="col-sm-8">
                                <input id="detailUrl" name="detailUrl" maxlength="100" th:value="${info.detailUrl}"
                                       class="form-control" type="text" placeholder="内链填赛事id 外链填Url">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button type="submit" class="btn btn-primary">保存</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript" src="/js/appjs/common/activity/edit.js"></script>
<script>

    var alists={};

    $(function () {
        sts();
    })


    function chooseFile() {
        $("#file").trigger("click");
    }

    function selectChange() {
        if ($("#isIo").val()==1){
            $("#types").show();
        } else{
            $("#types").hide();

        }
    }
   function uploadFile(){
       var client = new OSS.Wrapper({
           accessKeyId: alists.accessKeyId,
           accessKeySecret: alists.accessKeySecret,
           stsToken: alists.securityToken,
           endpoint: alists.endPoint,
           bucket: alists.bucketName
       });
       var timestamp = Date.parse(new Date());
       var file =$("#file");
       //storeAs表示上传的object name , file表示上传的文件
       client.multipartUpload(timestamp+".jpg", $("#file").get(0).files[0]).then(function (result) {
           parent.layer.msg("操作成功");
       }).catch(function (err) {
           parent.layer.msg("上传失败");

       });


   }



    function sts(){
        $.ajax({
            type : "GET",
            url : "/member/sts",
            error : function(request) {
                parent.layer.alert("Connection error");
            },
            success : function(data) {
                console.log(data);
                if (data.resultCode == '000') {
                    alists=data.data;
                }

            }
        });
    }

    function getFile(obj){
        var file=obj.files[0];
        if (file.size>3*1024*1024){
            $.alert({
                title:alertError,
                content:"上传图片不能大于3M"
            });
            return false;
        }
        if(!checkFileType(obj))
            return false;
        var reader = new FileReader();
        reader.readAsDataURL(file);
        console.log(file);
        reader.onload=function(e){
            $('#imgUrl').get(0).src = e.target.result;
        };
    }


</script>
</body>
</html>
